package data_structure;

public class SinglyLinkedList {//整体
    private Node head = null;//头指针

    /*
       节点类
    */
    private static class Node {
        int value;//值
        Node next;//下一个节点指针

        public Node(int value, Node next) {
            this.value = value;
            this.next = next;
        }
    }
    //添加值
    public void addFirst(int value) {
        //1.链表为空
        head = new Node(value,null);
        //2.链表非空
        head = new Node(value,head);
    }
    //遍历链表
    public void forEach() {
        Node point = head;//指针
        while(head != null) {
            System.out.println(point.value);
            point = point.next;
        }
    }

}
class SinglyLinkedList_Test {
    
}
